package com.bdmc.report.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.mybatisplus.core.ServicePlusImpl;
import com.bdmc.common.core.page.TableDataInfo;
import com.bdmc.report.domain.ReportCarAcc;
import com.bdmc.report.domain.bo.ReportCarAccBo;
import com.bdmc.report.domain.vo.ReportCarAccVo;
import com.bdmc.report.mapper.ReportCarAccMapper;
import com.bdmc.report.service.IReportCarAccService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 车辆点火熄火Service业务层处理
 *
 * @author bdmc
 * @date 2022-08-08
 */
@Service
public class ReportCarAccServiceImpl extends ServicePlusImpl<ReportCarAccMapper, ReportCarAcc, ReportCarAccVo> implements IReportCarAccService {

    @Override
    public ReportCarAccVo queryById(Long accId){
        return getVoById(accId);
    }

    @Override
    public TableDataInfo<ReportCarAccVo> queryPageList(ReportCarAccBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.mySelectPage(pageQuery.build(),bo));
    }

    @Override
    public TableDataInfo<ReportCarAccVo> mySelectPage(ReportCarAccBo bo, PageQuery pageQuery) {
        return TableDataInfo.build(baseMapper.mySelectPage(pageQuery.build(),bo));
    }

    @Override
    public List<ReportCarAccVo> queryList(ReportCarAccBo bo) {
        return baseMapper.mySelectPage(bo);
    }
    
    @Override
    public Boolean insertByBo(ReportCarAccBo bo) {
        ReportCarAcc add = BeanUtil.toBean(bo, ReportCarAcc.class);
        validEntityBeforeSave(add);
        boolean flag = save(add);
        if (flag) {
            bo.setAccId(add.getAccId());
        }
        return flag;
    }

    @Override
    public Boolean updateByBo(ReportCarAccBo bo) {
        ReportCarAcc update = BeanUtil.toBean(bo, ReportCarAcc.class);
        validEntityBeforeSave(update);
        return updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(ReportCarAcc entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return removeByIds(ids);
    }
}
